package com.zklh.leetcode.greedy.easy.problem392;
/**
 * @descrpiton 
 * @author 坐看落花
 * @version 1.0
 * @date 2020/6/1
 */
public class Solution {

    /**
     * 判断s(source) 是否是 t(target)的一个子序列 s = abc t = asdfbsdfc满足
     * @param s
     * @param t
     * @return
     */
    public boolean isSubsequence(String s, String t) {
        // 用于记录访问t的指针, s是作为层操作的, 遍历每层的层数就是s的指针
        int  tIndex = 0;
        boolean result = true;
        for (int i = 0; i < s.length(); i++) {
            result = false;
            while (tIndex < t.length()) {
                if (s.charAt(i) == t.charAt(tIndex++)) {
                    result = true;
                    break;
                }
                result = false;
            }
        }
        return result;
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.isSubsequence("abc", "ahbghc"));
        System.out.println(solution.isSubsequence("axc", "ahbghc"));
    }
}

